import config from "@/config"
import http from "@/utils/request"


// 产品   物资
export default {

  // 物资分类----------
  getCategoryList: {
    url: `${config.API_URL}/productCategory/list`,
    name: "获取物资分类列表",
    get: async function (data = {}) {
      return new Promise((resolve, reject) => {
        http.get(this.url, data).then((response) => {
          resolve(response)
        }).catch((error) => {
          resolve(error.data)
        })
      })
    }
  },

  addCategory: {
    url: `${config.API_URL}/productCategory/save`,
    name: "添加物资分类",
    post: async function (data = {}) {
      return new Promise((resolve, reject) => {
        http.post(this.url, data).then((response) => {
          resolve(response)
        }).catch((error) => {
          resolve(error.data)
        })
      })
    }
  },

  updateCategory: {
    url: `${config.API_URL}/productCategory/update`,
    name: "修改物资分类",
    post: async function (data = {}) {
      return new Promise((resolve, reject) => {
        http.post(this.url, data).then((response) => {
          resolve(response)
        }).catch((error) => {
          resolve(error.data)
        })
      })
    }
  },

  deleteCategory: {
    url: `${config.API_URL}/productCategory/delete`,
    name: "删除物资分类",
    post: async function (data = {}) {
      return new Promise((resolve, reject) => {
        http.postParam(this.url, data).then((response) => {
          resolve(response)
        }).catch((error) => {
          resolve(error.data)
        })
      })
    }
  },

  // 计量单位 ----------------------
  getUnitList: {
    url: `${config.API_URL}/productUnit/list`,
    name: "获取计量单位列表",
    get: async function (data = {}) {
      return new Promise((resolve, reject) => {
        http.get(this.url, data).then((response) => {
          resolve(response)
        }).catch((error) => {
          resolve(error.data)
        })
      })
    }
  },

  addUnit: {
    url: `${config.API_URL}/productUnit/add`,
    name: "添加计量单位",
    post: async function (data = {}) {
      return new Promise((resolve, reject) => {
        http.post(this.url, data).then((response) => {
          resolve(response)
        }).catch((error) => {
          resolve(error.data)
        })
      })
    }
  },

  updateUnit: {
    url: `${config.API_URL}/productUnit/update`,
    name: "修改计量单位",
    post: async function (data = {}) {
      return new Promise((resolve, reject) => {
        http.post(this.url, data).then((response) => {
          resolve(response)
        }).catch((error) => {
          resolve(error.data)
        })
      })
    }
  },

  deleteUnit: {
    url: `${config.API_URL}/productUnit/delete`,
    name: "删除计量单位",
    post: async function (data = {}) {
      return new Promise((resolve, reject) => {
        http.postParam(this.url, data).then((response) => {
          resolve(response)
        }).catch((error) => {
          resolve(error.data)
        })
      })
    }
  },

  // 商品管理 -----------

  getGoodsList: {
    url: `${config.API_URL}/product/list`,
    name: "获取商品列表",
    get: async function (data = {}) {
      return new Promise((resolve, reject) => {
        http.get(this.url, data).then((response) => {
          resolve(response)
        }).catch((error) => {
          resolve(error.data)
        })
      })
    }
  },

  getGoodsDetailById: {
    url: `${config.API_URL}/product/detailById`,
    name: "获取商品详情",
    post: async function (data = {}) {
      return new Promise((resolve, reject) => {
        http.postParam(this.url, data).then((response) => {
          resolve(response)
        }).catch((error) => {
          resolve(error.data)
        })
      })
    }
  },

  addGoods: {
    url: `${config.API_URL}/product/save`,
    name: "添加商品",
    post: async function (data = {}) {
      return new Promise((resolve, reject) => {
        http.post(this.url, data).then((response) => {
          resolve(response)
        }).catch((error) => {
          resolve(error.data)
        })
      })
    }
  },

  updateGoods: {
    url: `${config.API_URL}/product/update`,
    name: "修改商品",
    post: async function (data = {}) {
      return new Promise((resolve, reject) => {
        http.post(this.url, data).then((response) => {
          resolve(response)
        }).catch((error) => {
          resolve(error.data)
        })
      })
    }
  },

  deleteGoods: {
    url: `${config.API_URL}/product/delete`,
    name: "删除商品",
    post: async function (data = {}) {
      return new Promise((resolve, reject) => {
        http.postParam(this.url, data).then((response) => {
          resolve(response)
        }).catch((error) => {
          resolve(error.data)
        })
      })
    }
  },

  getAttrList: {
    url: `${config.API_URL}/attributeKey/list`,
    name: "获取商品属性列表",
    get: async function (data = {}) {
      return new Promise((resolve, reject) => {
        http.get(this.url, data).then((response) => {
          resolve(response)
        }).catch((error) => {
          resolve(error.data)
        })
      })
    }
  },

  addAttr: {
    url: `${config.API_URL}/attributeKey/add`,
    name: "添加商品属性",
    post: async function (data = {}) {
      return new Promise((resolve, reject) => {
        http.post(this.url, data).then((response) => {
          resolve(response)
        }).catch((error) => {
          resolve(error.data)
        })
      })
    }
  },

  deleteAttr: {
    url: `${config.API_URL}/attributeKey/delete`,
    name: "删除商品属性",
    post: async function (data = {}) {
      return new Promise((resolve, reject) => {
        http.postParam(this.url, data).then((response) => {
          resolve(response)
        }).catch((error) => {
          resolve(error.data)
        })
      })
    }
  },
}
